package com.trkj.controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojos.CcPatient;
import com.trkj.pojos.CcPrepayment;
import com.trkj.pojos.Tbstaff;
import com.trkj.service.CcDeductService;
import com.trkj.service.CcDeductdetailService;
import com.trkj.service.CcHospapplyService;
import com.trkj.service.CcOuthospitalService;
import com.trkj.service.CcPatientService;
import com.trkj.service.CcPaymentService;
import com.trkj.service.CcPrepaymentService;
import com.trkj.vo.CcPrepaymentVo;
import com.trkj.vo.HwcStaffVO;
import com.trkj.vo.Result;

@Controller
public class CcpatientController {

	@Autowired
	private CcPatientService ccpService;
	@Autowired
	private CcOuthospitalService ccOuthospitalService;
	@Autowired
	private CcHospapplyService chospService;
	@Autowired
	private CcPaymentService ccPaymentService;
	@Autowired
	private CcDeductService cddService;
	@Autowired
	private CcDeductdetailService cdddService;

	@Autowired
	private CcPrepaymentService ccPrepaymentService;
	@RequestMapping("/tocc_addccPayment")
	public @ResponseBody Result cc_addccPayment(String pmoney,String pmStaffid,String picid){
		CcPatient cp= ccpService.queryOneCcPatient(new BigDecimal(picid));
		if(cp!=null){
			ccPaymentService.addccpayment(new BigDecimal(pmoney), new BigDecimal(pmStaffid),cp.getPatientid());
			return new Result(true, "缴费成功！");		
		}else{
			return new Result(true, "医疗卡号不存在！");	
		}
		
	}
	@RequestMapping("/tocc_queryByOneCcPrepayment")
	public @ResponseBody List<CcPrepaymentVo> queryByOneCcPrepayment(String icid){
		return ccPrepaymentService.queryByOne(icid);
	}
	@RequestMapping("/tocc_queryByppmoney")
	public @ResponseBody Map<String, Object> toqueryByppmoney(int page,int rows){
		return ccPrepaymentService.queryByppmoney(page, rows);
	}
	@RequestMapping("/tocc_queryByAllpatient")
	public @ResponseBody Map<String, Object> queryByAllpatient(int page,int rows){
		
		return ccpService.queryAllPatient(page, rows);
	}
	@RequestMapping("/tocc_queryAllpatient")
	public @ResponseBody List<CcPatient> queryAllpatient(){
		
		return ccpService.findByAllCcPatient();
	}
	@RequestMapping("/tocc_queryByOnepatient")
	public @ResponseBody CcPatient queryByOnepatient(String pid){
		return ccpService.queryOneCcPatient(Long.parseLong(pid));
	}
	
	@RequestMapping("/tocc_queryByStaff")
	public @ResponseBody List<HwcStaffVO> queryByStaff(String deptid){
		return chospService.fidByTbstaff(new BigDecimal(deptid));
	}
	@RequestMapping("/tocc_updatepatientdoctor")
	public @ResponseBody Result updatepatientdoctor(CcPatient tb){
		ccpService.updateCcPatient(tb);
		return new Result(true, "修改成功！");		
	}
	@RequestMapping("/tocc_updatepatientpoffice")
	public @ResponseBody Result updatepatientpoffice(String offDoctorid,String patientid,
			String old_offid,String pname,String icid,String pofficesid,String padoctorid){
		ccpService.addCcSickOffice(offDoctorid, patientid, old_offid, pname, icid, pofficesid, padoctorid);
		return new Result(true, "修改成功！");		
	}
	@RequestMapping("/tocc_addCcOuthospital")
	public @ResponseBody Result addCcOuthospital(String patientid){
		long jg=ccOuthospitalService.addCcOuthospital(new BigDecimal(patientid));
		
		if(jg==0){
			return new Result(true, "申请提交成功！");	
		}else{
			return new Result(true, "申请不能重复提交！请等待工作人员审批！");	
		}	
	}
	@RequestMapping("/tocc_querypayment")
	public @ResponseBody Map<String, Object> cc_querypayment(int page,int rows,String icid,Date olddate,Date newdate){
		return cddService.queryCcDeduct(page, rows, icid,olddate,newdate);
	}
	@RequestMapping("/tocc_querydeductdetail")
	public @ResponseBody Map<String, Object> cc_querydeductdetail(int page,int rows,String deductid){
		return cdddService.queryByDeductid(page, rows, new BigDecimal(deductid));
	}
	@RequestMapping("/tocc_queryBypadoctorid")
	public @ResponseBody List<CcPatient> queryBypadoctorid(String padoctorid){
		return ccpService.queryCcPatient(padoctorid);
	}
}
